﻿function kpmgPopup(customOptions) {
    // private variables    
    this.options = $.extend({}, kpmgPopup.prototype.defaultOptions, customOptions || {});

    this.h = $(document).height();
    this.l = $(document).scrollLeft() + ($(document).width() - this.options.width) / 2;
    this.t = $(window).scrollTop() + ($(window).height() - 2 * this.options.height) / 2;

    this.uiBackground = $('<div id="ui-kpopup-bg" style=" height:' + this.h + 'px; background: #CCC; "></div>');
    this.uiIframe = $('<iframe id="ui-kpopup-iframe" src="javascript:void(0);" style="height:' + (this.h-10) + 'px;"></iframe>');
    this.uiContainer = $('<div id="ui-kpopup-container" style=\" width:' + this.options.width + 'px; left:' + this.l + 'px; top:' + this.t + 'px;height:auto;min-height:' + this.options.height + 'px;"></div>')

    this.initialize = function () {
        $("body").append(this.uiBackground).append(this.uiIframe).append(this.uiContainer);
    };

};
kpmgPopup.prototype.defaultOptions = { 'width': '500', 'height': '80' };



jQuery.KPMG = {

    isLive: function () {
        return $('#ui-kpopup-bg').length == 1 ? true : false;
    },

    closePopup: function () {
        $('#ui-kpopup-bg, #ui-kpopup-iframe, #ui-kpopup-container').remove();
        // to get focus on the document.
        $('#wrapper').focus();
    },

    loadPage: function (options) {
        if ($('#ui-kpopup-bg').length == 0) {
            var popup = new kpmgPopup(options);
            popup.initialize();
        }

        var container = $('#ui-kpopup-container');
        container.empty().append($('<div class="ui-kpopup-confirm">')
            .append($('<div class="title">&nbsp;' + (options.title == undefined ? '' : options.title) + '</div>')
                    .append($('<img id="ui-kpopup-closeImg" src="../images/_ui.close.gif" style="float:right; cursor:hand;  margin:5px 10px 0 0;">')
                    .click(function () {
                        jQuery.KPMG.closePopup();
                    })
                    )
                )
            .append($('<div class="content" style="border-bottom:3px solid #B2B2B2; "> ').append(options.content))
            );

    }

}
